﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace THenu.TinyHourseLib.DesignPattern.Builder_Pattern
{
    public class HouseBuilder : ActionBuilder
    {
        public HouseBuilder()
        {
            ActionList.Add(new ActionUnit("地基"));
            ActionList.Add(new ActionUnit("上房"));
            ActionList.Add(new ActionUnit("厢房"));
            ActionList.Add(new ActionUnit("厨房"));
            ActionList.Add(new ActionUnit("大门"));
            ActionList.Add(new ActionUnit("HouseBuilder Completed!"));
        }
        
    }
    public class CarBuilder : ActionBuilder
    {
        public CarBuilder()
        {
            ActionList.Add(new ActionUnit("发动机"));
            ActionList.Add(new ActionUnit("车厢"));
            ActionList.Add(new ActionUnit("车轮"));
            ActionList.Add(new ActionUnit("制动系统"));
            ActionList.Add(new ActionUnit("导航系统"));
            ActionList.Add(new ActionUnit("CarBuilder Completed!"));
        }

    }
    /// <summary>
    /// 建造代理
    /// </summary>
    public class ActionDirector
    {
        /// <summary>
        /// 执行指令序列
        /// </summary>
        /// <param name="builder"></param>
        public void Construct(ActionBuilder builder)
        {
            builder.ExecuteActionList();

        }
        /// <summary>
        /// 创建
        /// </summary>
        private static ActionDirector _Instance = new ActionDirector();
        /// <summary>
        /// 访问入口
        /// </summary>
        public static ActionDirector Instance
        {
            get { return _Instance; }
        }
    }
    /// <summary>
    /// 建造示例
    /// </summary>
    public class ActionBuilderPattern
    {

        public static void PatternShow()
        {
            ActionDirector ad = new ActionDirector();
            ad.Construct(new HouseBuilder());

            ad.Construct(new CarBuilder());
        }
    }


}
